﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchemaGraph.Interfaces;
using SchemaGraph.Interfaces.Edges;
using SchemaGraph.Interfaces.Vertexes;
using SchemaGraph.Edges;
using SchemaGraph.Vertexes;

namespace SchemaGraph
{
    public class EdgeCollection : GraphBase.EdgeCollection, IEdgeCollection
    {
        Graph m_graph;
        public EdgeCollection(VertexEnumerator vertexEnum, GraphBase.OnEdgeAdded edgeAdded
            , GraphBase.OnEdgeRemoved edgeRemoved, Graph graph)
            : base(vertexEnum, edgeAdded, edgeRemoved)
        {
            m_graph = graph;
        }

        #region IEdgeCollection Members

        public IExtensionEdge Extend(IDatatypeVertex parent, IDatatypeVertex child)
        {
            ExtensionEdge edge = new ExtensionEdge(parent, child);
            Construct(edge);
            return edge;
        }

        public IRestrictionEdge Restrict(IDatatypeVertex parent, IDatatypeVertex child)
        {
            RestrictionEdge edge = new RestrictionEdge(parent, child);
            Construct(edge);
            return edge;
        }

        public IListDerivationEdge DeriveList(ISimpleTypeVertex parent, ISimpleTypeVertex child)
        {
            ListDerivationEdge edge = new ListDerivationEdge((SimpleTypeVertex)parent, (SimpleTypeVertex)child);
            Construct(edge);
            return edge;
        }

        #endregion

        private void Construct(GraphBase.Edge edge)
        {
            edge.zzSetGraph(m_graph);
            base.Add(edge);
        }
    }
}
